import { Provide } from '@midwayjs/core';
import { IUserOptions } from '../interface';
import {SysUser} from "../entities/SysUser.entity";
import {InjectEntityModel} from "@midwayjs/typeorm";
import {Repository} from "typeorm";
import {UserSaveDto} from "../dto/UserSaveDto";


@Provide()
export class UserService {

  @InjectEntityModel(SysUser)
  sysUser: Repository<SysUser>;

  async getUser(options: IUserOptions) {
    return {
      uid: options.uid,
      username: 'mockedName',
      phone: '12345678901',
      email: 'xxx.xxx@xxx.com',
    };
  }

  async getUserList() {
    let allUsers = await this.sysUser.find({});
    return allUsers;
  }

  async saveUser(options: UserSaveDto) {
    let user = new SysUser();
    user.userName = options.userName;
    user.phonenumber = options.phonenumber;
    user.password = options.password;
    await this.sysUser.save(user);

  }
}
